<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Tag extends Model
{

    public function articlesTag()
    {
        return $this->hasMany(ArticlesTag::class, "tag_id", "id");
    }

    public function getList($isCount = false)
    {
        $query = $this->select("id", "name");
        return $isCount
            ? $query->withCount(["articlesTag"])->get()->toArray()
            : $query->get()->toArray();
    }
}
